//
//  YLPersonalnformationViewModel.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/1.
//  Copyright © 2017年 she1323. All rights reserved.
//  个人信息

#import "YLPersonalnformationViewModel.h"
#import "YLGlobeHeader.h"

#import "YLMyInfoModel.h"
#import "YLAccountTool.h"
#import "YLMyAdressModel.h"
@implementation YLPersonalnformationViewModel

- (void)loadData
{
    
    YLMyAdressModel *addressModel = [YLAccountTool account].defaultAddress;
    
    
    YLIconTitleModelGroup *group = self.groups.lastObject;

    
    {
        YLIconTitleContentModel *model5 = [YLIconTitleContentModel modelWithIcon:@"deliveryAddress" title:@"收货地址" content:@"点击添加" clickBlock:^NSString *{
            
            if (addressModel) {
                // 地址管理
                [self.adressManagerSubject sendNext:nil];
            } else {
                // 添加地址
                
                [self.addAdressSubject sendNext:nil];
            }
            
            return nil;
        }];
        
        
        if (addressModel > 0) {
            model5.content = [NSString stringWithFormat:@"%@ %@",addressModel.province , addressModel.city];
            model5.contentColor = YLLineColor;
        }
        [group.models replaceObjectAtIndex:group.models.count - 1 withObject:model5];
       // [self.group.models addObject:model5];
    }
    
}


- (NSArray<YLIconTitleModelGroup *> *)groups
{
    __weak typeof(self) weakSelf = self;
    if (!_groups) {
        _groups = [[NSMutableArray array] init];
        // 第一组
        {
            
            YLIconTitleModelGroup *group = [[YLIconTitleModelGroup alloc] init];
            [group.models addObject:[YLIconTitleNoArrowModel modelWithIcon:@"member" title:@"会员" content:_model.customerLevelName]];
        
            [_groups addObject:group];
        }
        
        
        // 第二组
        {
            YLIconTitleModelGroup *group = [[YLIconTitleModelGroup alloc] init];
           
            YLIconTitleContentModel *model1 = [YLIconTitleContentModel modelWithIcon:@"advisoryTelephone" title:@"我的手机" content:_model.tel clickBlock:^NSString *{
                return @"YLMyPhoneTableViewController";
            }];
            model1.contentColor = YLLineColor;
            
            
            [group.models addObject:model1];
            
            YLIconTitleContentModel *model2 = [YLIconTitleContentModel modelWithIcon:@"realNameAuthentication" title:@"实名认证" content:_model.identityID clickBlock:^NSString *{
                return @"YLRealNameInformationViewController";
            }];
            model2.contentColor = YLLineColor;
            
            [group.models addObject:model2];
            
            
            YLIconTitleModel *model3 = [YLIconTitleModel modelWithIcon:@"bandCard" title:@"银行卡" clickBlock:^NSString *{
                return @"YLMyBankCardListViewController";
               // return NSStringFromClass([YLChangeBankCardController class]);
            }];
            [group.models addObject:model3];
            
//            YLIconTitleContentModel *model4 = [YLIconTitleContentModel modelWithIcon:@"transactionPassword" title:@"安全口令" content:@"去设置" clickBlock:^NSString *{
//                [weakSelf.setSecurityPasswordSubject sendNext:nil];
//                return nil;
//            }];
//            
//            [group.models addObject:model4];
            
            {
                YLIconTitleContentModel *model5 = [YLIconTitleContentModel modelWithIcon:@"deliveryAddress" title:@"收货地址" content:@"点击添加" clickBlock:^NSString *{
                    
                    if (weakSelf.model.defaulReceiveAddress.length > 0) {
                        // 地址管理
                        [weakSelf.adressManagerSubject sendNext:nil];
                    } else {
                        // 添加地址
                        
                        [weakSelf.addAdressSubject sendNext:nil];
                    }
                    
                    return nil;
                }];
                

                
                if (_model.defaulReceiveAddress.length > 0) {
                    model5.content = _model.defaulReceiveAddress;
                    model5.contentColor = YLLineColor;
                }
                
                [group.models addObject:model5];
            }
            
            
            [_groups addObject:group];
        }
        
     
    }
    return _groups;
}

- (void)setShowCity:(NSString *)showCity
{
    _showCity = showCity;
    
    YLIconTitleModelGroup *group = self.groups.lastObject;
    YLIconTitleContentModel *model = group.models.lastObject;
    model.contentColor = YLLineColor;
    model.content = showCity;
    self.model.defaulReceiveAddress = showCity;
    
}

- (RACSubject *)adressManagerSubject
{
    if (!_adressManagerSubject) {
        _adressManagerSubject = [[RACSubject alloc] init];
    }
    return _adressManagerSubject;
}

- (RACSubject *)addAdressSubject
{
    if (!_addAdressSubject) {
        _addAdressSubject = [[RACSubject alloc] init];
    }
    return _addAdressSubject;
}


- (instancetype)init
{
    if (self = [super init]) {
        _setSecurityPasswordSubject = [RACSubject subject];
    }
    return self;
}
@end
